home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr54
/
bos2ol.zip
/
BOSS2OL.C
next >
Wrap
C/C++ Source or Header
|
1993-06-01
|
9KB
|
344 lines
#include <alltcc.h>
/****************************************************************************/
void ConvertTime(char *t);
void ConvertSchedule(char *inputLine, FILE *outfile);
void ConvertPhone(char *inputLine, FILE *outfile);
void ConvertBusiCard(char *inputLine, FILE *outfile);
void ConvertNovellBusiCard(char *inputLine, FILE *outfile);
/****************************************************************************/
void main(int argc, char *argv[])
{
FILE *infile,
*outfile;
static char
inputLine[512];
int i;
void (*Convert)(char *inputLine, FILE *outfile);
if (argc != 4)
exit(fprintf(stderr,
"Usage: B2S type infile outfile\n"
" 'type' can be one of the following\n"
" P = telePhone\n"
" B = Business card\n"
" N = Novell business card\n"
" S = Schedule\n"));
switch (toupper(argv[1][0]))
{
case 'P':
/* phone */
Convert = ConvertPhone;
break;
case 'B':
/* business card */
Convert = ConvertBusiCard;
break;
case 'N':
/* business card */
Convert = ConvertNovellBusiCard;
break;
case 'S':
/* schedule */
Convert = ConvertSchedule;
break;
default:
printf("That type is unknown!\n");
break;
}
infile = fopen(argv[2], "rt");
if (infile == NULL)
exit(fprintf(stderr, "Unable to open %s file\n", argv[2]));
outfile = fopen(argv[3], "wt");
if (outfile == NULL)
exit(fprintf(stderr, "Unable to open %s file\n", argv[3]));
while (fgets(inputLine, 512, infile) != NULL)
{
/* strip off the ending return / linefeed or space */
i = strlen(inputLine) - 1;
while (i >= 0 && inputLine[i] <= ' ')
inputLine[i--] = '\0';
printf("%s\n", inputLine);
Convert(inputLine, outfile);
}
fclose(infile);
fclose(outfile);
}
/****************************************************************************/
void ConvertSchedule(char *inputLine, FILE *outfile)
{
static char
description[512],
startTime[7],
endTime[7],
alarmTime[7];
int year,
month,
day;
/*
The format of the Casio (input) line is:
"1990-09-19","16:00","18:00","16:00","Webs"
"YYYY-MM-DD","START","END" ,"ALARM","DESCRIPTION"
The format of the Sharp (output) line is:
"03/25/1991","06:00p","09:00p","06:00p","FHE"
"MM/DD/YYYY","START" ,"END" ,"ALARM" ,"DESCRIPTION"
Operations to perform:
The date must be reformated
The times must be converted to 12 hour format
*/
sscanf(inputLine, "\"%d-%d-%d\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
&year, &month, &day,
startTime,
endTime,
alarmTime,
description);
ConvertTime(startTime);
ConvertTime(endTime);
ConvertTime(alarmTime);
fprintf(outfile, "\"%02d/%02d/%04d\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
month, day, year,
startTime,
endTime,
alarmTime,
description);
}
/****************************************************************************/
void ConvertTime(char *t)
{
int hours,
minutes;
char ampm = 'a';
if (sscanf(t, "%d:%d", &hours, &minutes) != 2)
t[0] = '\0';
else
{
if (hours >= 12)
ampm = 'p';
if (hours > 12)
hours -= 12;
if (hours == 0)
hours = 12;
sprintf(t, "%02d:%02d%c", hours, minutes, ampm);
}
}
/****************************************************************************/
void ConvertPhone(char *inputLine, FILE *outfile)
{
static char
name[384],
phone[384],
address[384],
spouse[384],
otherInfo[5][384];
int i;
/*
The format of the Casio (input) line is:
"Aaron Rhoades","226-0784","210 W 2000 S","JoAnna","","","","",""
The format of the Sharp (output) line is:
"AARON RHOADES","226-0784","210 W 2000 S"
Operations to perform:
convert to upper case
append spouse to end of name field
append 5 "other info's" to address
*/
strupr(inputLine);
sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
name, phone, address, spouse,
otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3], otherInfo[4]);
fprintf(outfile, "\"%s", name);
if (spouse[0])
fprintf(outfile, "\t%s", spouse);
fprintf(outfile, "\",\"%s\",\"%s", phone, address);
for (i = 0; i < 5; i++)
if (otherInfo[i][0])
fprintf(outfile, "\t%s", otherInfo[i]);
fprintf(outfile, "\"\n");
}
/****************************************************************************/
void ConvertBusiCard(char *inputLine, FILE *outfile)
{
static char
employeer[384],
name[384],
phone[384],
position[384],
department[384],
pobox[384],
address[384],
telex[384],
fax[384],
homeAddress[384],
homePhone[384],
otherInfo[4][384];
int i;
/*
The format of the Casio (input) line is:
"employer","name","phone","position","department","p.o. box",
"address","telex","fax","home address","home phone",
"free3",...
The format of the Sharp (output) line is:
"name","phone","address"
Operations to perform:
convert to upper case
append employeer, position, department to name
append telex, fax and home phone to phone
append p.o. box, home address and 4 frees to address
*/
strupr(inputLine);
sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
"\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
"\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
employeer, name, phone, position, department, pobox, address,
telex, fax, homeAddress, homePhone,
otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3]);
fprintf(outfile, "\"%s", name);
if (employeer[0])
fprintf(outfile, "\t%s", employeer);
if (position[0])
fprintf(outfile, "\t%s", position);
if (department[0])
fprintf(outfile, "\t%s", department);
fprintf(outfile, "\",\"%s", phone);
if (telex[0])
fprintf(outfile, "\t%s T", telex);
if (fax[0])
fprintf(outfile, "\t%s F", fax);
if (homePhone[0])
fprintf(outfile, "\t%s H", homePhone);
fprintf(outfile, "\",\"%s", address);
if (pobox[0])
fprintf(outfile, "\t%s", pobox);
if (homeAddress[0])
fprintf(outfile, "\t%s H", homeAddress);
for (i = 0; i < 4; i++)
if (otherInfo[i][0])
fprintf(outfile, "\t%s", otherInfo[i]);
fprintf(outfile, "\"\n");
}
/****************************************************************************/
void ConvertNovellBusiCard(char *inputLine, FILE *outfile)
{
static char
employeer[384],
name[384],
phone[384],
position[384],
department[384],
pobox[384],
address[384],
telex[384],
fax[384],
homeAddress[384],
homePhone[384],
otherInfo[4][384];
int i;
/*
The format of the Casio (input) line is:
"employer","name","phone","position","department","p.o. box",
"address","telex","fax","home address","home phone",
"free3",...
The format of the Sharp (output) line is:
"name","phone","address"
Operations to perform:
convert to upper case
trash employeer (we know it is NOVELL)
append position, department to name
append telex, fax and home phone to phone
append p.o. box, home address and 4 frees to address
*/
strupr(inputLine);
sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
"\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
"\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
employeer, name, phone, position, department, pobox, address,
telex, fax, homeAddress, homePhone,
otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3]);
fprintf(outfile, "\"%s", name);
if (position[0])
fprintf(outfile, "\t%s", position);
if (department[0])
fprintf(outfile, "\t%s", department);
fprintf(outfile, "\",\"%s", phone);
if (telex[0])
fprintf(outfile, "\t%s T", telex);
if (fax[0])
fprintf(outfile, "\t%s F", fax);
if (homePhone[0])
fprintf(outfile, "\t%s H", homePhone);
fprintf(outfile, "\",\"%s", address);
if (pobox[0])
fprintf(outfile, "\t%s", pobox);
if (homeAddress[0])
fprintf(outfile, "\t%s H", homeAddress);
for (i = 0; i < 4; i++)
if (otherInfo[i][0])
fprintf(outfile, "\t%s", otherInfo[i]);
fprintf(outfile, "\"\n");
}
/****************************************************************************/
/****************************************************************************/